﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@model TaoPortal.Areas.Admin.Models.FileManageModel
<div class="row-fluid">
    <div class="span24">
        <form tabindex="0" class="form-horizontal" id="searchForm">
            <div class="row-fluid show-grid">
                <div class="span24">
                    <label class="control-label control-label-auto">文件分类：</label>
                    <div class="controls" id="FClassID">
                        @Html.HiddenFor(x => x.Searcher.FClassID)
                    </div>
                    <label class="control-label control-label-auto" style="margin-left: 5px">文件名称：</label>
                    <div class="controls">
                        @Html.TextBoxFor(x => x.Searcher.FName, new { @class = "input-normal" })
                    </div>
                    <label class="control-label control-label-auto" style="margin-left: 5px">上传日期：</label>
                    <div class="controls">
                        @Html.TextBoxFor(x => x.Searcher.StartDate, new { @class = "calendar" }) - @Html.TextBoxFor(x => x.Searcher.EndDate, new { @class = "calendar" })
                    </div>
                    <button class="button button-small" style="margin-left: 5px" id="btnSearch" type="submit">搜索</button>
                </div>
            </div>
        </form>
        <div id="grid">
        </div>
    </div>
</div>
<script type="text/javascript">
    var Overlay = BUI.Overlay
    var dialog = null;
    var tree = null;
    //日期控件
    BUI.use('bui/calendar', function (Calendar) {
        var datepicker = new Calendar.DatePicker({
            trigger: '.calendar',
            autoRender: true
        });
    });
    //文章分类
    BUI.use(['bui/extensions/treepicker', 'bui/tree', 'bui/data'], function (TreePicker, Tree, Data) {
        //数据缓冲类
        var treeData = eval('@Html.Raw(Model.FileClass)');
        //由于这个树，不显示根节点，所以可以不指定根节点
        var tree = new Tree.TreeList({
            nodes: treeData,
            //dirSelectable: false,//阻止树节点选中
            showLine: true //显示连接线
        });

        var picker = new TreePicker({
            width: '120',
            children: [tree] //配置picker内的列表
        });
        var select = new BUI.Select.Select({
            render: '#FClassID',
            width: '120',
            picker: picker,
            forceFit: false, //不强迫列表跟选择器宽度一致
            valueField: '#Searcher_FClassID'
        }).render();
    });

    //列表
    var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
      { title: '文件名称', width: 150, sortable: false, dataIndex: 'FName' },
      {
          title: '文件地址', width: 250, sortable: false, dataIndex: 'ID', renderer: function (value, obj) {
              return '<input type="text" style="width:232px" readonly="readonly" value="/File/' + value + '" />';
          }
      },
      { title: '类型', width: 70, sortable: false, dataIndex: 'FExtName' },
      { title: '大小', width: 70, sortable: false, dataIndex: 'FLength' },
      { title: '上传时间', width: 150, sortable: false, dataIndex: 'CreateTime' },
      {
          title: '操作', width: 50, sortable: false, dataIndex: 'ID',
          renderer: function (value, obj) {
              return '<span class="grid-command" onclick="parent.SelectFile(\'' + obj.ID + '\',\'' + obj.FName + '\')" >选择</span>';
          }
      }
    ];
    //加载列表
    var store = new Store({
        url: '/Admin/FileManage/AjaxGetList',
        proxy: {
            limitParam: 'pageSize',
            method: 'post'
        },
        autoLoad: true,
        pageSize: 10
    }),
    grid = new Grid.Grid({
        render: '#grid',
        loadMask: true,
        forceFit: true,
        plugins: [Grid.Plugins.AutoFit],
        columns: columns,
        store: store,
        bbar: {
            pagingBar: true
        }
    });
    grid.render();
    //搜索
    var form = $('#searchForm')[0];
    $(form).on('submit', function (ev) {
        ev.preventDefault();
        var obj = BUI.FormHelper.serializeToObject(form);
        obj.pageIndex = 0;
        obj.start = 0;
        store.load(obj);
    });

</script>
